package com.haima.ziliao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haima.common.annotation.RepeatSubmit;
import com.haima.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PJiajiao;
import com.haima.ziliao.service.IPJiajiaoService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 家教Controller
 * 
 * @author hima
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/ziliao/jiajiao")
public class PJiajiaoController extends BaseController
{
    @Autowired
    private IPJiajiaoService pJiajiaoService;

    /**
     * 查询家教列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiao:list')")
    @GetMapping("/list")
    public TableDataInfo list(PJiajiao pJiajiao)
    {
        startPage();
        List<PJiajiao> list = pJiajiaoService.selectPJiajiaoList(pJiajiao);
        return getDataTable(list);
    }

    @GetMapping("/queryJiajiao")
    public AjaxResult queryJiajiao(PJiajiao pJiajiao)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao==null){
            return AjaxResult.error(201,"未注册");
        }else{
            return AjaxResult.success(jiajiao);
        }
    }
    @GetMapping("/editInfo")
    public AjaxResult editInfo(PJiajiao pJiajiao)
    {
        pJiajiaoService.updatePJiajiao(pJiajiao);
        return AjaxResult.success();
    }
    @GetMapping("/getDetail")
    public AjaxResult getDetail(PJiajiao pJiajiao)
    {
        PJiajiao jiajiao = pJiajiaoService.selectPJiajiaoById(pJiajiao.getId());
        return AjaxResult.success(jiajiao);
    }

    @GetMapping("/getJiajiaoList")
    public TableDataInfo getJiajiaoList(PJiajiao pJiajiao)
    {
        startPage();
        List<PJiajiao> list = pJiajiaoService.selectPJiajiaoList(pJiajiao);
        return getDataTable(list);
    }

    @GetMapping("/applyReg")
    @RepeatSubmit
    public AjaxResult applyReg(PJiajiao pJiajiao)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao==null){
            pJiajiao.setUid(SecurityUtils.getUserId());
            pJiajiaoService.insertPJiajiao(pJiajiao);
            return AjaxResult.success("已注册");
        }else{
            return AjaxResult.error("已注册");
        }
    }

    @GetMapping("/editXuexiao")
    @RepeatSubmit
    public AjaxResult editXuexiao(String biye)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao!=null){
            jiajiao.setBiye(biye);
            pJiajiaoService.updatePJiajiao(jiajiao);
            return AjaxResult.success("已注册");
        }else{
            return AjaxResult.error("更新失败");
        }
    }
    @GetMapping("/getWechat")
    public AjaxResult getWechat()
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        return AjaxResult.success("ok",jiajiao.getWechat());
    }

    @GetMapping("/editWechat")
    @RepeatSubmit
    public AjaxResult editWechat(String wechat)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao!=null){
            jiajiao.setWechat(wechat);
            pJiajiaoService.updatePJiajiao(jiajiao);
            return AjaxResult.success("ok");
        }else{
            return AjaxResult.error("更新失败");
        }
    }

    @GetMapping("/editZhuanye")
    @RepeatSubmit
    public AjaxResult editZhuanye(String zhuanye)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao!=null){
            jiajiao.setZhuanye(zhuanye);
            pJiajiaoService.updatePJiajiao(jiajiao);
            return AjaxResult.success("已注册");
        }else{
            return AjaxResult.error("更新失败");
        }
    }

    @GetMapping("/editXueke")
    @RepeatSubmit
    public AjaxResult editXueke(String xueke)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao!=null){
            jiajiao.setXueke(xueke);
            pJiajiaoService.updatePJiajiao(jiajiao);
            return AjaxResult.success("已注册");
        }else{
            return AjaxResult.error("更新失败");
        }
    }

    @GetMapping("/editMiaoshu")
    @RepeatSubmit
    public AjaxResult editMiaoshu(String miaoshu)
    {
        PJiajiao jiajiao = pJiajiaoService.getOne(new QueryWrapper<PJiajiao>().eq("uid", SecurityUtils.getUserId()));
        if(jiajiao!=null){
            jiajiao.setMiaoshu(miaoshu);
            pJiajiaoService.updatePJiajiao(jiajiao);
            return AjaxResult.success("已注册");
        }else{
            return AjaxResult.error("更新失败");
        }
    }

    /**
     * 导出家教列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiao:export')")
    @Log(title = "家教", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PJiajiao pJiajiao)
    {
        List<PJiajiao> list = pJiajiaoService.selectPJiajiaoList(pJiajiao);
        ExcelUtil<PJiajiao> util = new ExcelUtil<PJiajiao>(PJiajiao.class);
        util.exportExcel(response, list, "家教数据");
    }

    /**
     * 获取家教详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiao:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pJiajiaoService.selectPJiajiaoById(id));
    }

    /**
     * 新增家教
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiao:add')")
    @Log(title = "家教", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PJiajiao pJiajiao)
    {
        return toAjax(pJiajiaoService.insertPJiajiao(pJiajiao));
    }

    /**
     * 修改家教
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiao:edit')")
    @Log(title = "家教", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PJiajiao pJiajiao)
    {
        return toAjax(pJiajiaoService.updatePJiajiao(pJiajiao));
    }

    /**
     * 删除家教
     */
    @PreAuthorize("@ss.hasPermi('ziliao:jiajiao:remove')")
    @Log(title = "家教", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pJiajiaoService.deletePJiajiaoByIds(ids));
    }
}
